function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)return unescape(r[2]);
    return null;
}

/**
 * 乘法函数
 */
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try {
        m += s1.split(".")[1].length;
    }
    catch (e) {
    }
    try {
        m += s2.split(".")[1].length;
    }
    catch (e) {
    }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}
/**
 * 除法函数
 */

function accDiv(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try {
        t1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
    }
    try {
        t2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
    }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""));
        r2 = Number(arg2.toString().replace(".", ""));
        return (r1 / r2) * pow(10, t2 - t1);
    }
}
/**
 * 加法函数
 */
function accAdd(arg1, arg2) {
    var r1, r2, m;
    try {
        r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
        r1 = 0;
    }
    try {
        r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
        r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2));
    return (arg1 * m + arg2 * m) / m;
}
/**
 * 减法函数
 */
function Subtr(arg1, arg2) {
    var r1, r2, m, n;
    try {
        r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
        r1 = 0;
    }
    try {
        r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
        r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2));
    //last modify by deeka
    //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}
/**
 * 序列化对象
 */
$.fn.serializeObject = function () {
    var obj = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (obj[this.name] !== undefined) {
            if (!obj[this.name].push) {
                obj[this.name] = [obj[this.name]];
            }
            obj[this.name].push(this.value || '');
        } else {
            obj[this.name] = this.value || '';
        }
    });
    return obj;
};

/**
 *
 * 上传图片预览功能
 *
 * @param file
 * @param width
 * @param height
 */

function upload_image(file, width, height) {
    if (file.files && file.files[0]) {
        var img = document.getElementById("preview");
        var reader = new FileReader();
        reader.onload = function (evt) {
            img.src = evt.target.result;
        };
        reader.readAsDataURL(file.files[0]);
    }
    else {
        var div = document.getElementById("header-img");
        var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
        file.select();
        file.blur();
        var src = document.selection.createRange().text;
        div.innerHTML = '<img id="preview" class="preview">';
        var imgObj = document.getElementById("preview");
        var $img = $('#preview');
        imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
        imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src;
        div.innerHTML = "<p id=preview style='width:" + width + "px;height:" + height + "px;" + sFilter + src + "\"'></p>";
    }
}

/**
 * ajax上传图片
 *
 * @param url
 * @param id
 * @param asset
 * @param w
 * @param h
 * @param vId
 */

function uploadFile(url, id, asset, w, h, vId) {
    $('.popup-layer').show();
    $.ajaxFileUpload({
        url: url,
        fileElementId: id, //文件上传域的ID
        secureuri: false,
        dataType: 'json', //返回值类型 一般设置为json
        contentType: 'text/html',
        success: function (responseText)  //服务器成功响应处理函数
        {
            if (responseText.errorCode == 0) {
                img_path = responseText.data.path_name;
                vId.attr({'src': asset + img_path, 'width': w, 'height': h});
                $('.popup-layer').hide();
            } else {
                alert(responseText.message);
                $('.popup-layer').hide();
            }
        },
        error: function (responseText, status, e)//服务器响应失败处理函数
        {
            alert(e);
            $('.popup-layer').hide();
        }
    });
}

/**
 * 截取字符串
 *
 * @param text
 * @param len
 *
 */

function interceptAction(text, len) {
    var inter_s = text;                  //要展示的字符串

    var re_str;

    if (inter_s.length > len) {
        re_str = inter_s.substring(0, len) + "...";
    }

    return re_str;
}

/**
 * 侧边栏高亮
 *
 */

// 父级侧边栏
function SidebarHighlighting(id) {
    var this_id = '';
    $('.sidebar-list').each(function() {
        var $this = $(this);
        this_id = $(this).data('id');
        if (id == this_id) {
            $this.addClass('sidebar-list-active');
            SidebarOpen($this, id);
        }
    })
}

// 子集侧边栏
function SonSidebar(parent_id, this_id) {
    $('.son-sidebar li a').each(function() {
        var $this = $(this);

        var this_son_id = $this.data('id');
        if (this_id == this_son_id) {
            switch (parent_id) {
                case '2':
                    $this.addClass('sidebar-son-list-active');
                    break;
                case '7':
                    $this.addClass('sidebar-son-list-active');
                    break;
                case '8':
                    $this.addClass('sidebar-son-list-active');
                    break;
            }
        }
    })
}

function SidebarOpen(is, id) {
    // 控制手风琴特效
    is.parents('.panel.panel-default').find('.panel-collapse').addClass('in');

    // 控制左侧图标的颜色
    var is_class = is.find('.sidebar-icon span').attr('class');
    is.find('.sidebar-icon span').addClass(is_class+'-c');

    // 带子列表的  ->  右侧icon变化
    if (id == '2' || id == '7' || id == '8') {
        is.find('.r-arrow').addClass('down-arrow');
    }
}

//点击侧边栏
$(function(){
    $('.sidebar-list').on('click',function(){
        var id = $(this).data('id');

        if (id == '2' || id == '7' || id == '8') {
            $(this).find('.r-arrow').toggleClass('down-arrow');
        }
    })
});